import { getAllCategory } from '@/api/category'
// 分类模块
const state = {
  list: [
    '居家',
    '美食',
    '服饰',
    '母婴',
    '个护',
    '严选',
    '严选',
    '数码',
    '杂项'
  ]
}
const mutations = {
  setList (state, payload) {
    state.list = payload
  },
  // 鼠标移入显示
  show (state, item) {
    if (item.id) {
      state.list.find(v => v.id === item.id).open = true
    }
  },
  // 鼠标移出或点击隐藏
  hide (state, item) {
    if (item.id) {
      state.list.find(v => v.id === item.id).open = false
    }
  }
}
const actions = {
  async getAllCategory ({ commit }) {
    const { result } = await getAllCategory()
    result.forEach(item => {
      item.open = false
    })
    commit('setList', result)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
